const tokenKey = 'blog_token'
const publicKay = 'ua_publicKay'

//用于将token存入localStorage
export function saveToken(token) {
  localStorage.setItem(tokenKey, token)
}

//用于从localStorage中读取token
export function readToken() {
  return localStorage.getItem(tokenKey)
}

//从localStoragre删除用户token
export function deleteToken() {
  localStorage.removeItem(tokenKey)
}

// 用于将公钥存入localStorage
export function savePublicKey(publicKey) {
  localStorage.setItem(publicKay, publicKey)
}

//用于从localStorage中读取公钥
export function readPublicKey() {
  return localStorage.getItem(publicKay)
}

//从localStoragre删除公钥
export function deletePublicKey() {
  localStorage.removeItem(publicKay)
}

// 存入用户信息
export function saveUserInfo(userInfo) {
  localStorage.setItem('userInfo', JSON.stringify(userInfo))
}

// 读取用户信息
export function readUserInfo() {
  const userInfo = localStorage.getItem('userInfo')
  if (userInfo) {
    return JSON.parse(userInfo)
  } else {
    return null
  }
}

// 删除用户信息
export function deleteUserInfo() {
  localStorage.removeItem('userInfo')
}

// 判断银狐是否登录
export function isUserLoggedIn() {
  // 这里实现检查用户登录状态的逻辑
  return !!readToken()
}
